;(function ($,window,document,undefined){
	
	CP.OrderStep2Module = function (callback){

		this.$el = null;
		this.$btnBack = null;
		this.$btnSubmit = null;

		this.$howtopay = null;
		this.$tennguoinhan = null;
		this.$phonenguoinhan = null;
		this.$diachigiaohang = null;
		this.$sharing = null;

		this.viewPath = "js/module/order.module.v1/view/step2.html";

		this.callbackOrderModule = callback;
	};

	CP.OrderStep2Module.prototype.init = function(successHandle){

		var that = this;

		// RENDER LAYOUT
		
		$.get(this.viewPath, function(tmp) {
			var source = $(tmp).html();
			var template = Handlebars.compile(source);
			
			that.$el = $(template());

			that.$btnBack = that.$el.find('.back');

			that.$btnSubmit = that.$el.find('.check-out-submit');

			that.$howtopay = that.$el.find('.how-to-pay');
			that.$tennguoinhan = that.$el.find('.ten-nguoi-nhan');
			that.$phonenguoinhan = that.$el.find('.phone_nguoi_nhan');
			that.$diachigiaohang = that.$el.find('.dia-chi-giao-hang');
			that.$sharing = that.$el.find('.share-member');

			that.bindEvent();
		
			successHandle.call(this);

		});

	};

	CP.OrderStep2Module.prototype.show = function () {
		this.$el.addClass('animated fadeInLeft');
		this.$el.removeClass('hidden');
	}

	CP.OrderStep2Module.prototype.hide = function () {
		this.$el.addClass('hidden');
		this.$el.removeClass('animated fadeInLeft');
	}

	CP.OrderStep2Module.prototype.getElement = function () {
		return this.$el;
	}

	CP.OrderStep2Module.prototype.bindEvent = function () {
		this.$btnBack.bind('click', this.backHandle.bind(this));
		this.$btnSubmit.bind('click', this.submitOrderAndNextToStep3.bind(this));
	}

	//CONTROLLER
	CP.OrderStep2Module.prototype.backHandle = function () {
		this.callbackOrderModule.backHandle.call(this.callbackOrderModule);
	}
	CP.OrderStep2Module.prototype.submitOrderAndNextToStep3 = function () {
		// this.callbackOrderModule.submitOrderAndNextToStep3.call(this.callbackOrderModule);

		if(this.checkValidate()){
			console.log(this.getValue());
			this.callbackOrderModule.submitOrderAndNextToStep3.call(this.callbackOrderModule);
		}
		
	}

	CP.OrderStep2Module.prototype.checkValidate = function () {
		console.log('Check Validate');
		return true;
	}

	CP.OrderStep2Module.prototype.getValue = function () {

		var data = {
			phuongthucthanhtoan : this.$howtopay.val(),
			tennguoinhan : this.$tennguoinhan.val(),
			phone_nguoinhan : this.$phonenguoinhan.val(),
			diachinguoinhan : this.$diachigiaohang.val(),
			is_sharing : this.$sharing.attr("checked") ? 0 : 1,
		}
		return data;
	}


	MYLIB.mixin(CP.OrderStep2Module, MYLIB.Event.ObserverMixin);

})(jQuery,window,document)